<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>个人课程列表</title>
    <script src="/jquery/jquery-3.2.1.min.js"></script>
    <script src="/layui/layui.js"></script>
    <link rel="stylesheet" href="/layui/css/layui.css">
</head>

<style>
    *{
        margin: 0;
        padding: 0;
    }
    .box{
        width: 100%;
        height: 1030px;
    }
    .list{
        width: 1650px;
        height: 50px;
        margin-left: 20px;
        background-color:rgb(243,243,243);
    }
    .list-left-left{
        width: 10px;
        height: 30px;
        float: left;
        margin-top: 10px;
        background: green;
    }
    .list-left-right{
        width: 80px;
        height: 30px;
        font-size: 14px;
        line-height: 50px;
        float: left;
        text-indent: 5px;
    }
    .list-right{
        float: right;
        margin-top: 5px;
        margin-right: 45px;
    }

    .query{
        width: 1650px;
        height: 100px;
        margin-top: 20px;
        margin-left: 20px;
    }
    .layui-col-md11{
        width: 100%;
    }
    .layui-card-header{
        background-color:rgb(243,243,243);
    }
    .layui-form-label{
        width: 120px;
    }
    .layui-form-item .layui-input-inline {
        float: left;
        width: 305px;
        margin-right: 10px;
    }

    .record{
        width: 1650px;
        height: 821px;
        margin-top: 40px;
        margin-left: 20px;
        background-color:rgb(243,243,243);
    }
    .import{
        margin-left: 870px;
    }
    #button_ids{
        display: none;
    }
    .record-left{
        width: 300px;
        float: left;
    }
    .record-right{
        width: 1350px;
        height: 700px;
        margin-left: 25px;
        float: left;
    }
    .layui-table-cell {
        line-height: 47px;
        height: inherit;
    }
    .layui-table-cell>a{
        color:green;
    }
    .layui-table-fixed {
        position: absolute;
        left: 0px;
        top: 0px;
        z-index: 101;
    }
    div#rMenu {position:absolute; visibility:hidden; top:0; background-color: #555;text-align: left;padding: 2px;}
    div#rMenu ul li {
        margin: 1px 0;
        padding: 0 5px;
        cursor: pointer;
        list-style: none outside none;
        background-color: #DFDFDF;
    }
    .query-top-right{
        float: right;
        margin-right: 30px;
    }
    img{
        width: 100px;
        height: 116px;
    }
</style>
<body>
    <div class="box">
        <!--商品列表-->
        <div class="list">
            <div class="list-left">
                <div class="list-left-left"></div>
                <p class="list-left-right">个人课程</p>
            </div>
            <div class="list-right">
                <div class="list-right-left layui-btn layui-icon layui-icon-refresh" onclick="refresh()">&nbsp;刷新</div>
                <div class="list-right-right layui-btn layui-icon layui-icon-left" id="goBack">&nbsp;返回</div>
            </div>
        </div>
        <!--筛选查询-->
        <div class="layui-row query">
            <div class="layui-col-md11">
                <div class="layui-card headerCenter">
                    <div class="layui-card-header backColor">
                        <i class="layui-icon">&#xe615;</i>
                        筛选查询
                        <div class="query-top-right layui-btn" onclick="retrieval()">高级检索</div>
                    </div>
                    <div class="layui-card-body">
                        <form class="layui-form">
                            <div class="layui-form-item">
                                <label class="layui-form-label">课程名称：</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="courseName" required lay-verify="required" placeholder="请输入商品名称" autocomplete="off" class="layui-input">
                                </div>

                                <label class="layui-form-label">课程关键字：</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="coursePrimary" required lay-verify="required" placeholder="请输入商品关键字" autocomplete="off" class="layui-input">
                                </div>

                                <label class="layui-form-label">课程价格：</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="courseNprice" required lay-verify="required" placeholder="请输入商品价格" autocomplete="off" class="layui-input">
                                </div>

                                <span>
                                    <button type="button" class="layui-btn" onclick="search()">
                                        <i class="layui-icon layui-icon-search"></i> 搜索
                                    </button>
                                    <button type="reset" class="layui-btn layui-btn-warm">
                                        <i class="layui-icon layui-icon-refresh"></i> 重置
                                    </button>
                                </span>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

        <!--数据列表-->
        <div class="record">
            <div class="record-right">
                <!--表-->
                <table id="demoTable" lay-filter="demoTable"></table>
            </div>
        </div>
        <!--表头样式-->
        <div id="button_ids">
            <i class="layui-icon layui-icon-align-left"></i> 个人课程列表
        </div>

        <!--表内操作-->
        <div id="button_caozuo" style="display:none" >
            <a alt="查看" title="查看"  lay-event="selectTable">查看</a>
            <a alt="删除" title="删除"  lay-event="deleteTable">删除</a>
        </div>

    </div>
    <!-- 高级检索 -->
    <input type="hidden" name="ProductRetrieval" id="ProductRetrieval"/>
    <input type="hidden" name="title" id="title"/>
    <input type="hidden" name="productLabel" id="productLabel"/>
</body>
<script>
    layui.use(['jquery','layer','table','form'],function(){
        var $=layui.jquery;
        var layer=layui.layer;
        var table=layui.table;
        var form = layui.form;
        var updateDate = "";
        var createTime = "";
        //获取user
        var user = localStorage.getItem("user");
        user = JSON.parse(user);
        var id = user.data.userId;

        //表格
        getTable();
        function getTable(){
            $.ajax({
                url:"/course/getCourseByCreateId",
                type:"post",
                dataType:"json",
                data:{"createId" : id},
                success:function (data) {
                    demoTable(data.data);
                }
            })
        }

        //表格
        function demoTable(data){
            var tableRender = table.render({
                elem:'#demoTable',
                title:"委托书",
                data:data,
                toolbar:'#button_ids',
                limit:10,
                width:1600,
                page:{
                    layout:['count','prev','page','next','limit','skip','refresh'],
                    limits:[10,20,30],
                    first:"首页",
                    last:"尾页",
                },
                cols:[[
                    {type:'checkbox',width:50},
                    {field:"courseId",title:"课程序号",align:'center',width:140},
                    {field:"url",title:"课程图片",align:'center',width:150,templet:function(data){
                            return '<img src="'+data.url+'"';
                        }},
                    {field:"courseName",title:"课程名称",align:'center',width:150},
                    {field:"coursePrimary",title:"关键字",align:'center',width:150},
                    {field:"courseNprice",title:"现价",align:'center',width:140},
                    {field:"result",title:"审核状态",align:'center',width:140,templet:function(data){
                            if(data.result==1){
                                return '审核通过';
                            }else if(data.result==2){
                                return '待审核';
                            }else{
                                return '审核驳回';
                            }
                            return '<p>'+data.result+'</p><p style="color: #00B83F">审核详情</p>';
                        }},
                    {field:"courseStatus",title:"状态",align:'center',width:125,templet:function(data){
                            if(data.courseStatus==2){
                                return '<input type=\"checkbox\" value="'+data.courseId+'" lay-skin=\"switch\" lay-text=\"上架|下架"\ checked lay-filter="switchTest">';
                            }else if(data.courseStatus==3){
                                return '<input type=\"checkbox\" value="'+data.courseId+'" lay-skin=\"switch\" lay-text=\"上架|下架" lay-filter="switchTest"\>';
                            }else if(data.courseStatus==4){
                                return '<p>已删除</p>';
                            }
                        }},
                    {field:"saleNum",title:"销量",align:'center',width:160,templet:function(data){
                            if(data.saleNum==null){
                                return 0;
                            }else {
                                return data.saleNum;
                            }
                        }
                    },
                    {field:"name",title:"商品分类",align:'center',width:125},
                    {field:"courseIntro",title:"商品标签",align:'center',width:125},
                    {field:'',title:"操作",align:'center',width:125,toolbar:'#button_caozuo'}
                ]],
            })

        }

        //监听课程的上下架状态并修改状态
        form.on('switch(switchTest)', function(data){
            if(data.elem.checked==true){
                $.ajax({
                    url:"/course/updateCourseStatus",
                    type:"post",
                    dataType:"json",
                    data:{'courseStatus':2,'courseId':data.value},
                    success:function (data) {
                        getTable();
                        layer.msg("修改成功");
                    }
                })
            }else{
                $.ajax({
                    url:"/course/updateCourseStatus",
                    type:"post",
                    dataType:"json",
                    data:{'courseStatus':3,'courseId':data.value},
                    success:function (data) {
                        getTable();
                        layer.msg("修改成功");
                    }
                })
            }
        })

        //搜索个人课程的模糊查
        getTableSearch = function getTableSearch(courseName,coursePrimary,courseNprice,id){
            $.ajax({
                url:"/course/getCourseByCreateIdSearch",
                type:"post",
                dataType:"json",
                data:{'courseName':courseName,'coursePrimary': coursePrimary,'courseNprice':courseNprice,'createId':id},
                success:function (data) {
                    demoTable(data.data);
                }
            })
        };

        //搜索
        search = function search(){
            var courseName = $("input[name=courseName]").val();
            var coursePrimary = $("input[name=coursePrimary]").val();
            var courseNprice = $("input[name=courseNprice]").val();
            getTableSearch(courseName,coursePrimary,courseNprice,id);
        }

        //高级检索
        retrieval = function retrieval(){
            var user = localStorage.getItem('user');
            user = JSON.parse(user);
            var createId = user.data.userId;
            layer.open({
                type : 2,
                title : "高级检索",
                area : [ '900px', '550px' ],
                shade : 0,
                offset: 'auto',
                content :"/curriculum/courselist/course-sample.html",
                btn:["确认","取消"],
                yes:function(index,layero){
                    var child = layero.find('iframe').contents();
                    var courseId = child.find("input[name=courseId]").val();
                    var courseNprice = child.find("input[name=courseNprice]").val();
                    var name = child.find("#name option:selected").val();
                    var courseName = child.find("input[name=courseName]").val();
                    var coursePrimary = child.find("input[name=coursePrimary]").val();
                    var trueName = child.find("input[name=trueName]").val();
                    var param = {
                        'courseId': courseId,
                        'courseNprice': courseNprice,
                        'name': name,
                        'courseName': courseName,
                        'coursePrimary' : coursePrimary,
                        'trueName': trueName,
                        'createId':createId,
                    }
                    $.ajax({
                        url:"/course/getCourseByCreateIdRetrieval",
                        data:param,
                        type:"post",
                        dataType:"json",
                        success:function (data) {
                            if(data!=null){
                                demoTable(data.data);
                            }
                            layer.close(index);
                        }
                    })
                },
            })
        }

        //右边工具栏操作
        table.on('tool(demoTable)',function (obj) {
            localStorage.setItem("courseData",JSON.stringify(obj.data));
            var event = obj.event;
            if (event == "selectTable"){
                getTime();
                var editar = {
                    'logType':2,
                    "type":5,
                    "userId":obj.data.createId,
                    'createDate':createTime,
                    'remark':'查看反馈统计',
                }
                $.ajax({
                    url:"/JsLog/addProductJsLog",
                    data:editar,
                    type:'post',
                    dataType:'text',
                    success:function (data) {
                    }
                });
                layer.open({
                    type:2,
                    title:"查看",
                    area:["95%","99%"],
                    offset:'auto',
                    btn:["确定","取消"],
                    content:"/curriculum/courselist/course-list-tool-select.html",
                    success:function(layero,index){
                        var child = layero.find('iframe').contents();
                        child.find("#courseName").text(obj.data.courseName);
                        child.find("#createDate").text(obj.data.createDate);
                        child.find("#trueName").text(obj.data.trueName);
                        child.find("#courseNprice").text(obj.data.courseNprice);
                        child.find("#coursePrimary").text(obj.data.coursePrimary);
                        child.find("#className").text(obj.data.name);
                        if(obj.data.likeNum==null){
                            child.find("#likeNum").text(0);
                        }else{
                            child.find("#likeNum").text(obj.data.likeNum);
                        }
                        if(obj.data.collectNum==null){
                            child.find("#collectNum").text(0);
                        }else{
                            child.find("#collectNum").text(obj.data.collectNum);
                        }
                        child.find("#courseInfo").text(obj.data.courseInfo);
                        child.find("#courseIntro").text(obj.data.courseIntro);
                        child.find("#url").attr("src",obj.data.url);
                        child.find("#video").attr("src",obj.data.courseUrl);

                    },
                    yes:function( index,layero){
                        layer.close(index);
                    },
                    btn2:function(index,layero){
                        layer.close(index);
                    },
                    end:function (layero, index) {
                        layer.close(index);
                    }
                });
            }else if(event == "deleteTable"){
                var courseId = obj.data.courseId;
                layer.confirm('确认要删除吗?', {icon: 3, title:'提示'}, function(index){
                    getTime();
                    var editar = {
                        'logType':2,
                        "type":3,
                        "userId":obj.data.createId,
                        'createDate':createTime,
                        'remark':'删除反馈统计',
                    }
                    $.ajax({
                        url:"/JsLog/addProductJsLog",
                        data:editar,
                        type:'post',
                        dataType:'text',
                        success:function (data) {
                        }
                    });
                    $.ajax({//删除商品
                        url:"/course/delCourseByCourseId",
                        data:{'courseId' : courseId},
                        type:'post',
                        dataType:'json',
                        success:function (data) {
                            $.ajax({//删除审核记录
                                url:"/course/delCourseRecord",
                                data:{'courseId': courseId},
                                type:'post',
                                dataType:'json',
                                success:function (data) {
                                    layer.msg("删除成功");
                                }
                            })
                            getTable();
                        }
                    });
                });
            }else{
                console.log("点到我你就败了");
            }
        });

        //刷新
        refresh =function refresh(){
            location.reload();
        };

        //返回
        $('#goBack').click(function () {
            var iframe = parent.$('.iframe');
            $.each(iframe,function (i,item) {
                if('个人课程' == $(item).attr('_href')){
                    parent.$('#beforeHref').val($(item).attr('_href'));
                    parent.beforeHref();
                    return;
                }
            });
        });

        //现在时间
        function getTime(){
            var date=new Date();
            var year=date.getFullYear();
            var month=date.getMonth()+1;
            var day=date.getDate();
            var hour=date.getHours();
            var minute=date.getMinutes();
            var second=date.getSeconds();
            var dateStr = year+"-"+zeroFilling(month)+"-"+zeroFilling(day)+" "+zeroFilling(hour)+":"+zeroFilling(minute)+":"+zeroFilling(second);
            updateDate = dateStr;
            createTime = dateStr;
        }
        function zeroFilling(data){
            if(data<10){
                data="0"+data;
            }
            return data;
        }

    });
</script>

</html>